import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import format from '@dfeidao/atom-nodejs/dt/format';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';
interface Message {
	productid: string;
	teacher_no: string;
	page_no: number;
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:app-teacher-class/s001,action_id:' + action_id);
	const ret = await complex_query(action_id, session_id, systemid);
	const data1 = await ret.add_field('class_record', 'date', 'date').add_field('class_record', 'week', 'week').add_field('class_record', 'grade', 'grade').add_field('class_record', 'class_name', 'class_name').add_field('class_record', 'teacher_name', 'teacher_name').add_field('class_record', 'subject_name', 'subject_name').add_field('class_record', 'start_time', 'start_time').add_field('class_record', 'finish_time', 'finish_time').add_field('class_record', 'section', 'section').where_eq('class_record', 'teacher_no', message.teacher_no)
		.where_eq('class_record', 'productid', message.productid).page(20, message.page_no).exec() as [{ recording_time: number, date: string }];
	data1.forEach((i) => {
		i.date = format(Number(i.date), 'YYYY-MM-DD');
	});
	log('Service end path:app-teacher-class/s001,action_id:' + action_id);
	return { data: data1 } as IWebResult;
}
